package week04.graph01;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhangxiaokun on 2018/2/28.
 */
public class Picture extends Graphic {
    private List<Graphic> leafsList = new ArrayList<>();

    @Override
    public void draw() {
        System.out.println(" ********** 画picture ********** ");
        for (Graphic graphic : leafsList) {
            graphic.draw();
        }
    }

    @Override
    public void add(Graphic graphic) {
        leafsList.add(graphic);
    }

    @Override
    public boolean remove(Graphic graphic) {
        if (leafsList.contains(graphic)) {
            leafsList.remove(graphic);
            return true;
        }
        return false;
    }

    @Override
    public Graphic getChild(int index) {
        if (index >= 0 && index < leafsList.size()) {
            return leafsList.get(index);
        }
        return null;
    }

    @Override
    public List<Graphic> getAllChild() {
        return leafsList;
    }
}
